package markgame2dphys;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.util.LinkedList;

import net.phys2d.math.Vector2f;

public final class MarkGameGraphics {

	private Graphics2D g;
	
	private LinkedList<AffineTransform> transforms;
	
	public MarkGameGraphics(Graphics2D g) {
		this.g = g;
		transforms = new LinkedList<AffineTransform>();
	}
	
	public void pushTransform(){
		transforms.push(g.getTransform());
	}
	public void popTransform(){
		g.setTransform(transforms.pop());
	}

	public void setColor(Color color) {
		g.setColor(color);
	}

	public void drawOval(float x, float y, float width, float height) {
		g.drawOval((int)(x+0.5f), (int)(y+0.5f), (int)(width+0.5f), (int)(height+0.5f));
	}
	
	public void drawCircle(float cx, float cy, float radius){
		drawOval(cx-radius, cy-radius, 2*radius, 2*radius);
	}
	
	public void drawCircle(Vector2f center, float radius){
		drawCircle(center.x, center.y, radius);
	}

	public void drawLine(float x1, float y1, float x2, float y2) {
		g.drawLine((int)(x1+0.5f), (int)(y1+0.5f), (int)(x2+0.5f), (int)(y2+0.5f));
	}
	
	public void drawLine(Vector2f point1, Vector2f point2){
		drawLine(point1.x, point1.y, point2.x, point2.y);
	}

	public void rotate(float theta, float x, float y) {
		g.rotate(theta, (int)(x+0.5f), (int)(y+0.5f));
	}
	
	public void rotate(float theta, Vector2f center){
		rotate(theta, center.x, center.y);
	}

	public void drawRect(float x, float y, float width, float height) {
		g.drawRect((int)(x+0.5f), (int)(y+0.5f), (int)(width+0.5f), (int)(height+0.5f));
	}
	
	public void drawRect(Vector2f origin, float width, float height){
		drawRect(origin.x, origin.y, width, height);
	}
	
	public void drawBox(float cx, float cy, float width, float height){
		drawRect(cx-width/2, cy-height/2, width, height);
	}
	
	public void drawBox(Vector2f center, float width, float height){
		drawBox(center.x, center.y, width, height);
	}

	public void translate(float x, float y) {
		g.translate(x, y);
	}
	
	public void translate(Vector2f desloc){
		translate(desloc.x, desloc.y);
	}

	public void drawPolygon(Vector2f[] points) {
		for (int i = 0; i < points.length; i++) {
			int j = i+1;
			if(j >= points.length)
				j = 0;

			drawLine(points[i], points[j]);
		}
	}

	public void fillRect(float x, float y, float width, float height) {
		g.fillRect((int)(x+0.5f), (int)(y+0.5f), (int)(width+0.5f), (int)(height+0.5f));
	}
	
	
	
}
